﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VoL.Domain.Dtos.HealthEducation;
using VoL.Domain.Infrastructure;
using VoL.Domain.IServices.HealthEducation;
using VOL.Core.Utilities;
using VOL.Entity.DomainModels;
using Microsoft.EntityFrameworkCore;

namespace VoL.Domain.Services.HealthEducation
{
    /// <summary>
    /// 健康宣教
    /// </summary>
    public class HealthEducationServices : IHealthEducationServices
    {
        private readonly IBaseRepository<Bed> _bedRepository;
        private readonly IBaseRepository<BroadCast> _broadCastRepository;
        private readonly IBaseRepository<BroadCastManage> _broadCastManageRepository;
        private readonly IBaseRepository<BroadCastTemplate> _broadCastTemplateRepository;

        public HealthEducationServices(IBaseRepository<Bed>bedRepository,IBaseRepository<BroadCast>broadCastRepository,IBaseRepository<BroadCastManage> broadCastManageRepository,IBaseRepository<BroadCastTemplate> broadCastTemplateRepository)
        {
            this._bedRepository = bedRepository;
            this._broadCastRepository = broadCastRepository;
            this._broadCastManageRepository = broadCastManageRepository;
            this._broadCastTemplateRepository = broadCastTemplateRepository;
        }
        public async Task<WebResponseContent> GetBroadCastManage()
        {
            var result = new WebResponseContent();
            var query =
                from a in _broadCastManageRepository.GetAll()
                join b in _broadCastRepository.GetAll() on Convert.ToInt32(a.BroadCastContent) equals b.Id
                join c in _bedRepository.GetAll() on a.BedId equals c.WardCode
                join d in _broadCastTemplateRepository.GetAll() on Convert.ToInt32(a.TemplateName) equals d.Id
                select new BroadCastManageDto
                {
                    Id = a.Id,
                    BroadCastTypeId = a.BroadCastTypeId,
                    WardCode = a.WardId,
                    BroadCastContentId = b.Id,
                    BroadCastContent = b.BroadCastContent,
                    TemplateNameId = d.Id,
                    TemplateName = d.TemplateName,
                };
            var list = await query.ToListAsync();
            result.Data = list;
            return result;
        }

    }
}
